<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
#jquery-table td {
	cursor: pointer !important
}
.load_bg {
	background: #000;
	opacity: 0.1;
	left: 0px;
	top: 0px;
	position: fixed;
	height: 100%;
	width: 100%;
	overflow: hidden;
	z-index: 10000;
}

.load_img {
	left: 50%;
	top: 180px;
	position: fixed;
	height: 50px;
	overflow: hidden;
	z-index: 20000;
}
</style>
</head>
<body class="no-skin">
	<div class="load_bg" style="display: none;"></div>
	<img src="http://img.xmiles.cn/commentloading.gif" class="load_img"
		style="display: none" />
	<div class="page-content">
		<div class="page-header"
			style="margin-bottom: 0px; padding-bottom: 10px;"></div>

		<form id="queryForm">
			<div class="page-content-area">
				<div class="row">
					<div class="col-sm-12">
						<div class="widget-box"
							style="border: 0px solid #ccc; border-top: none; border-bottom: none;">
							<div class="widget-header widget-header-blue widget-header-flat">
								<h4 class="widget-title">选择条件进行查询</h4>
								<div class="widget-toolbar">
									<a href="#" data-action="collapse"> <i
										class="ace-icon fa fa-chevron-up"></i>
									</a>
								</div>
							</div>
							<div class=" widget-body">
								<div class="widget-main">
								    
								    <div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" style="text-align: right"
											for="sex">日期:</label>
										<div class="col-sm-8" style="padding-left: 0px">
										    <div class="input-daterange input-group">
												<input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" id="startDate" name="startDate"> 
												 <span class="input-group-addon" style="width: 6px"> 
												    <i class="fa fa-exchange"></i>
												 </span>
												 <input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" id="endDate" name="endDate">
											 </div>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">平台:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="platform">
												<option value="">全部</option>
												<option value="android">安卓</option>
												<option value="ios">ios</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">产品</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select id="prdid" name="prdid" class="form-control"></select>
										</div>
									</div>

									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">推广活动ID:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="new_activity_id">
												<option value="">全部</option>
												<option value="1">渠道推广</option>
												<option value="2">联登推广</option>
												<option value="3">API推广</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">推广活动类型:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="new_activity_type">
												<option value="">全部</option>
												<option value="1">渠道推广</option>
												<option value="2">联登推广</option>
												<option value="3">API推广</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">渠道:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select id="channel" name="channel"></select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">位置:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<input type="text" style="padding-left: 0px;" name="position"
												id="position">
										</div>
									</div>

									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">页面:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<input type="text" name="page">
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">模块:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<input type="text" style="padding-left: 0px;" name="ck_module" id="ck_module">
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">环境:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="environment">
												<option value="">全部</option>
												<option value="1">H5</option>
												<option value="2">客户端</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">用户类型:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="user_type">
												<option value="">全部</option>
												<option value="1">老用户</option>
												<option value="2">新用户</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">合作方:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="api_type">
												<option value="">---请选择---</option>
												<option value="1">捷信福贷</option>
												<option value="2">宜信信贷</option>
												<option value="3">恒昌</option>
												<option value="4">小雨点网贷</option>
												<option value="6">我来贷</option>
												<option value="10">信而富</option>
												<option value="11">点融</option>
												<option value="12">小树普惠</option>
												<option value="14">51贷吧</option>
												<option value="15">中安信业</option>
												<option value="18">五号米库</option>
												<option value="19">优款</option>
												<option value="20">立借</option>
												<option value="22">借云</option>
												<option value="24">快来贷</option>
												<option value="25">诚信钱包-半流程</option>
												<option value="27">中腾信</option>
												<option value="28">魔借-新</option>
												<option value="29">友信</option>
												<option value="34">小钱花</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">订单类型:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="order_type">
												<option value="">全部</option>
												<option value="1">站内API</option>
												<option value="2">一键投递API</option>
											</select>
										</div>
									</div>
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" 
										       style="text-align:right" >申请状态:</label>
										 <div class="col-sm-8" style="padding-left: 0;">
											<select name="status" class="form-control">
												<option value="">---请选择---</option>
												<option value="1">订单初始化</option>
												<option value="2">验证账号失败</option>
												<option value="3">订单审核中</option>
												<option value="4">合作方取消</option>
												<option value="5">初审成功</option>
												<option value="6">申请成功</option>
												<option value="7">合作方退回</option>
												<option value="9">订单提交失败</option>
												<option value="12">合作方已放款</option>
												<option value="16">订单已提交</option>
											</select>
										</div>
									</div>
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">是否按渠道查询:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="is_channel">
												<option value="1">是</option>
												<option value="2">否</option>
											</select>
										</div>
									</div>
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">请求来源:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="request_source">
												<option value="">全部</option>
												<option value="1">菠萝贷</option>
												<option value="2">银河黑卡</option>
											</select>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="col-md-12 center">
						<div class="clearfix form-actions">
							<button class="btn btn-purple  no-border" type="button"
								name="btn-query" onclick="query_any()" id="btn-query">
								<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
								查询
							</button>
							&nbsp;&nbsp;&nbsp;
					        <button class="btn btn-grey  no-border" type="reset">
						     <i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
						              重置
					         </button>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
					   <a href="javascript:void(0)" class="btn btn-success btn-small"
					      id="output" onclick="loadlist()">导出列表</a>
						<table id="jquery-table"
							class="table table-striped table-bordered table-hover">
						</table>
					</div>
				</div>
			</div>
		</form>
	</div>

	<%@ include file="/common/common-js.jsp"%>
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<script type="text/javascript" src="${ctx}/ace/js/jquery.dataTables.min.js"></script>
	
	<script type="text/javascript">
	
		function loadlist() {
			var form = document.forms["queryForm"];
			form.action = ctx + "/loanorder/exportStatData.action";
			form.submit();
		}
		
		var souceList = null;
		//【查询】按钮Click事件
		function query_any() {
			$(".load_bg").removeAttr("style");
			$(".load_img").removeAttr("style");
			if (jqTable != null) {
				jqTable.fnDraw();
			} else {
				loaddata();
			}
			$("#output").show();
		}
		var jqTable = null;
		var loaddata = function() {
			jQuery(function($) {
				jqTable = $('#jquery-table').dataTable(
					{
						 //数据列控制（包括对应返回JSON属性名称，对应表头列索引位置、数据转换封装等）
						 "columnDefs" : [
							{
								"title" : '日期',
								"name" : "date",
								"data" : "date",
								"targets" : [ 0 ],
								"bSortable" : false,
							},
							{
								"title" : '产品',
								"name" : "product_name",
								"data" : "product_name",
								"targets" : [ 1 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							},
							{
								"title" : '平台',
								"name" : "platform",
								"data" : "platform",
								"targets" : [ 2 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							}, 
							{
								"title" : "渠道",
								"name" : "channel_name",
								"data" : "channel_name",
								"targets" : [ 3 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							}, 
							{
								"title" : "推广活动类型",
								"name" : "new_activity_type",
								"data" : "new_activity_type",
								"targets" : [ 4 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							}, 
							{
								"title" : "推广活动ID",
								"name" : "new_activity_id",
								"data" : "new_activity_id",
								"targets" : [ 5 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							}, 
							{
								"title" : "环境",
								"name" : "environment",
								"data" : "environment",
								"targets" : [ 6 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value < 0){
										return "全部";
									} else if (value == 1) {
										return "菠萝贷推广H5";
									} else if (value == 2) {
										return "菠萝贷客户端";
									} else {
										return "--";
									}
								}
							},
							{
								"title" : "请求来源",
								"name" : "request_source",
								"data" : "request_source",
								"targets" : [ 7 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value < 0){
										return "全部";
									} else if (value == 1) {
										return "菠萝贷";
									} else if (value == 2) {
										return "银河黑卡";
									} else {
										return "--";
									}
								}
							},
							{
								"title" : "用户类型",
								"name" : "user_type",
								"data" : "user_type",
								"targets" : [ 8 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value < 0){
										return "全部";
									} else if (value == 1) {
										return "老用户";
									} else if (value == 2) {
										return "新用户";
									} else {
										return "--";
									}
								}
							},
							{
								"title" : "页面",
								"name" : "page",
								"data" : "page",
								"targets" : [ 9 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							},

							{
								"title" : "模块",
								"name" : "ck_module",
								"data" : "ck_module",
								"targets" : [ 10 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							}, 
							{
								"title" : "位置",
								"name" : "position",
								"data" : "position",
								"targets" : [ 11 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							}, 
							{
								"title" : '合作方',
								"targets" : [ 12 ],
								"name" : "third_name",
								"data" : "third_name",
								"class" : "center",
								"bSortable" : false,
								"width" : "100px",
								"render" : function(value, type, row) { // 返回自定义内容
									if(value == null){
										return "--";
									} else {
										if(value < 0) {
										   return "全部";
										}
										return value;
									}
								}
							},
							{
								"title" : "订单类型",
								"name" : "order_type",
								"data" : "order_type",
								"targets" : [ 13 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if(value < 0){
										return "全部";
									} else if (value == 1) {
										return "站内";
									} else if (value == 2) {
										return "一键投递API";
									} else {
										return "--";
									}
								}
							},
							{
								"title" : "请求API资料人数",
								"name" : "api_count",
								"data" : "api_count",
								"targets" : [ 14 ],
								"bSortable" : false,
								"width" : "5%",
								"render" : function(value, type, row) { // 返回自定义内容
									if (value != null) {
										return value;
									} else {
										return "--";
									}
								}
							}, 
							{
								"title" : "请求API资料甲方数",
								"name" : "api_source_count",
								"data" : "api_source_count",
								"targets" : [ 15 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if (value == null) {
										return "--";
									} else {
										return value;
									}
								}
							}, 
							{
								"title" : "提交API人数",
								"name" : "submit_count",
								"data" : "submit_count",
								"targets" : [ 16 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if (value == null) {
										return "--";
									} else {
										return value;
									}
								}
							}, 
							{
								"title" : "提交API甲方数",
								"name" : "submit_source_count",
								"data" : "submit_source_count",
								"targets" : [ 17 ],
								"bSortable" : false,
								"render" : function(value, type, row) { // 返回自定义内容
									if (value == null) {
										return "--";
									} else {
										return value;
									}
								}
							},],
							"sAjaxSource" : ctx + "/loanorder/stat_list.action",
							"fnServerData" : function(sSource, aoData,
									fnCallback) {//从服务器请求数据
								var data = $('#queryForm').serializeObject();
								data.aoData = JSON.stringify(aoData);
								$.ajax({
									"dataType" : 'json',
									"type" : "POST",
									"url" : sSource,
									"data" : data,
									"success" : function(resp) {
										$(".load_bg").attr("style",
												"display:none");
										$(".load_img").attr("style",
												"display:none");
										$("#hidden_pass").attr("style",
												"display:block");
										$('#jquery-table').removeClass(
												"dataTable");
										fnCallback(resp);
										initListPage();
									},
									"error" : function(XMLHttpRequest,
											textStatus, errorThrown) {
										$(".load_bg").attr("style",
												"display:none");
										$(".load_img").attr("style",
												"display:none");
										alert('请求服务器错误,请刷新重试！！'); //错误提示，包括服务器重启导致的session失效
									}
								});
							},
							"fnRowCallback" : function(nRow, aData,
									iDisplayIndex, iDisplayIndexFull) {
							},
							"bDestroy" : true,
							"bScrollInfinite" : true,
							"sScrollXInner" : "100%",
							"sScrollY" : "100%",//如果不设置，IE会有问题
							"aaSorting" : [ [ 0, "desc" ] ]
						//初始化加载，默认按第几列排序、排序方式（列从0开始计算）
						});
			});
		}

		function initDate() {
			var today = GetDateStr(0);
			var beforedate = GetDateStr(-5);
			if ($.isBlank($("#startDate").val())) {
				jQuery("#startDate").val(beforedate);
			}
			if ($.isBlank($("#endDate").val())) {
				jQuery("#endDate").val(today);
			}
		}

		function GetDateStr(AddDayCount) {
			var dd = new Date();
			dd.setDate(dd.getDate() + AddDayCount);//获取AddDayCount天后的日期
			var y = dd.getFullYear();
			var m = dd.getMonth() + 1;//获取当前月份的日期
			var d = dd.getDate();
			return y + "-" + m + "-" + d;
		}

		//时间控件
		jQuery(function($) {
			$(".date-picker").datepicker({
				autoclose : true
			}).next().on(ace.click_event, function() {
				$(this).prev().focus();
			});
		});

		$(document).ready(function() {
			initDate();
			loadChannel();
			loadProduct();
			$("#channel").combobox();
			$("#output").hide();
		});
	</script>
</body>
</html>